package com.abso.mp3tunes.locker.core.data;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.dom4j.Element;

/**
 * The login data is the information returned as a result of a login attempt.
 */
public class LoginData extends AbstractLockerData {

	/** The status code. */
	private int status;

	/** The session identifier. */
	private String sessionId;

	/** The name of the user. */
	private String username;

	/** The error message. */
	private String errorMessage;

	/**
	 * Constructs a new login data.
	 * 
	 * @param responseElem
	 *            the &lt;mp3tunes&gt; XML element.
	 */
	public LoginData(Element responseElem) {
		this.status = LockerDataUtils.getInt(responseElem, "status", -1);
		this.sessionId = LockerDataUtils.getString(responseElem, "session_id");
		this.username = LockerDataUtils.getString(responseElem, "username");
		this.errorMessage = LockerDataUtils.getString(responseElem,
				"errorMessage");
	}

	/**
	 * Returns the status: 1 on success, or 0 on failure.
	 * 
	 * @return the status.
	 */
	public int getStatus() {
		return status;
	}

	/**
	 * Returns the session identifier.
	 * 
	 * @return the session identifier.
	 */
	public String getSessionId() {
		return sessionId;
	}

	/**
	 * Returns the username.
	 * 
	 * @return the username.
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * Returns the error message.
	 * 
	 * @return the error message
	 */
	public String getErrorMessage() {
		return errorMessage;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}

}
